Developer Documentation

QuickTime 4 API Documentation

QuickTime 4 Reference

| Previous | Chapter Contents | Chapter Top | Next |

Writing Movie Data

As with reading movie data, data handlers provide two distinct write facilities. The DataHPutData function is a simple synchronous interface that allows applications to append data to the end of a container.

The DataHWrite function is a more capable, asynchronous write function that is suitable for movie capture operations. As is the case with the DataHScheduleData function, your component calls the application's data-handler completion function when you are done with the write request.

There are several other helper functions that allow applications to prepare your data handler for a movie capture operation. The DataHCreateFile function asks your component to create a new container. The DataHSetFileSize and DataHGetFileSize functions work with a container's size, in bytes. The DataHGetFreeSpace function allows applications to determine when to make a container larger. The DataHPreextend function asks your component to make a container larger. Applications may call your component's DataHGetPreferredBlockSize function in order to determine how best to interact with your data handler.

Before writing data to a data reference, applications must call your component's DataHOpenForWrite function to open a write path to the container. The DataHCloseForWrite function closes that write path.

Note that some data handlers may not support write operations. For example, some shared devices, such as a CD-ROM "jukebox," may be read-only devices. As a result, it is very important that your data handler correctly report its write capabilities to client programs. See "Selecting a Data Handler" for information about the functions that client programs use to interrogate your data handler. For more information on writing movie data, see "Storing Movie Data" .

DataHOpenForWrite

Your component opens its current data reference for write-only access.

pascal ComponentResult DataHOpenForWrite (DataHandler dh);
dh
Identifies the calling program's connection to your data handler component.

DISCUSSION

After setting your component's current data reference by calling the DataHSetDataRef function, client programs call the DataHOpenForWrite function in order to start writing to the data reference. Your component should open the data reference for write-only access. If the data reference is already open or cannot be opened, return an appropriate error code.

RESULT CODES

dataAlreadyOpenForWrite
-2044 Data reference already open for write

DataHCloseForWrite

Your component closes write-only access to its data reference.

pascal ComponentResult DataHCloseForWrite (DataHandler dh);
dh
Identifies the calling program's connection to your data handler component.

DISCUSSION

Note that a client program may close its connection to your component (by calling the Component Manager's CloseComponent function) without closing the write path. If this happens, your component should close the data reference before closing the connection.

RESULT CODES

dataNotOpenForWrite
-2043 Data reference not open for write
dataAlreadyClosed
-2045 This reference already closed

DataHPutData

Your component writes data to its current data reference. This is a synchronous write operation that appends data to the end of the current data reference.

pascal ComponentResult DataHPutData (
                     DataHandler dh,
                     Handle h,
                     long hOffset,
                     long *offset,
                     long size);
dh
Identifies the calling program's connection to your data handler component.

h
Specifies the handle that contains the data to be written to the data reference.

hOffset
Identifies the offset into the handle h to the data to be written.

offset
Contains a pointer to a long. Your component returns the offset in the data reference at which your component wrote the data.

size
Specifies the number of bytes to write.

DISCUSSION

The DataHPutData function provides a high-level write interface. This is a synchronous write operation that only appends data to the end of the current data reference. That is, the client program's execution is blocked until your component returns control from this function, and the client cannot control where the data is written. As a result, most movie-capture clients (for example, Apple's sequence grabber component) use the DataHWrite function to write data when creating movies.

RESULT CODES

dataNotOpenForWrite
-2043 Data reference not open for write

SEE ALSO

Client programs can force your component to write any cached data by calling your component's DataHFlushData function.

DataHWrite

Your component writes data to its current data reference. This can be a synchronous write operation or an asynchronous operation, and can write data to any location in the container.

pascal ComponentResult DataHWrite (
                     DataHandler dh,
                     Ptr data,
                     long offset,
                     long size,
                     DHCompletionUPP completion,
                     long refCon);
dh
Identifies the calling program's connection to your data handler component.

data
Specifies a pointer to the data to be written. Client programs should lock the memory area holding this data, allowing your component's DataHWrite function to move memory.

offset
Specifies the offset (in bytes) to the location in the current data reference at which to write the data.

size
Specifies the number of bytes to write.

completion
Contains a pointer to a data-handler completion function. When your data handler finishes with the client program's write request, your component must call this routine. Be sure to call this routine even if the request fails. Your component should pass the reference constant that the client program provided with the refCon parameter.

The client program must provide a completion routine for all asynchronous write requests. For synchronous requests, client programs should set this parameter to nil .

refCon
Contains a reference constant that your data handler component should provide to the data-handler completion function specified with the completion parameter.

For synchronous operations, client programs should set this parameter to 0.

DISCUSSION

The DataHWrite function provides both a synchronous and an asynchronous write interface. Synchronous write operations work like the DataHPutData function--the data handler component returns control to the client program only after it has serviced the write request. Asynchronous write operations allow client programs to queue write requests. Your data handler queues the request and immediately returns control to the calling program. After your component actually writes the data, it calls the client program's data-handler completion function.

RESULT CODES

dataNotOpenForWrite
-2043 Data reference not open for write

SEE ALSO

Client programs can force your component to write any cached data by calling your component's DataHFlushData function.

DataHSetFileSize

Your component sets the size, in bytes, of the current data reference.

pascal ComponentResult DataHSetFileSize (
                     DataHandler dh,
                     long fileSize);
dh
Identifies the calling program's connection to your data handler component.

fileSize
Specifies the new size of the container corresponding to the current data reference, in bytes.

DISCUSSION

The DataHSetFileSize function is functionally equivalent to the File Manager's SetEOF function. If the client program specifies a new size that is greater than the current size, your component should extend the container to accommodate that new size. If the client program specifies a container size of 0, your component should free all of the space occupied by the container.

DataHGetFileSize

Your component returns the size, in bytes, of the current data reference.

pascal ComponentResult DataHGetFileSize (
                     DataHandler dh,
                     long *fileSize);
dh
Identifies the calling program's connection to your data handler component.

fileSize
Contains a pointer to a long. Your component returns the size of the container corresponding to the current data reference, in bytes.

DISCUSSION

The DataHGetFileSize function is functionally equivalent to the File Manager's GetEOF function.

DataHCreateFile

Your component creates a new container that meets the specifications of the current data reference.

pascal ComponentResult DataHCreateFile (
                     DataHandler dh,
                     OSType creator,
                     Boolean deleteExisting);
dh
Identifies the calling program's connection to your data handler component.

creator
Specifies the creator type of the new container. If the client program sets this parameter to 0, your component should choose a reasonable value (for example, 'TVOD' , the creator type for Apple's movie player).

deleteExisting
Indicates whether to delete any existing data. If this parameter is set to true and a container already exists for the current data reference, your component should delete that data before creating the new container. If this parameter is set to false , your component should preserve any data that resides in the container defined by the current data reference (if there is any).

DataHGetPreferredBlockSize

The DataHGetPreferredBlockSize function allows your component to report the block size that it prefers to use when accessing the current data reference.

pascal ComponentResult DataHGetPreferredBlockSize (
                     DataHandler dh,
                     long *blockSize);
dh
Identifies the calling program's connection to your data handler component.

blockSize
Contains a pointer to a long. Your component returns the size of blocks (in bytes) it prefers to use when accessing the current data reference.

DISCUSSION

Different devices use different file system block sizes. This function allows your component to report its preferred block size to the client program. Note that the client program is not required to use this block size when making requests. Some clients may, however, try to accommodate your component's preference.

DataHGetFreeSpace

Your component reports the number of bytes available on the device that contains the current data reference.

pascal ComponentResult DataHGetFreeSpace (
                     DataHandler dh,
                     unsigned long *freeSize);
dh
Identifies the calling program's connection to your data handler component.

freeSize
Contains a pointer to an unsigned long. Your component returns the number of bytes of free space available on the device that contains the container referred to by the current data reference.

DataHPreextend

Your component allocates new space for the current data reference, enlarging the container.

pascal ComponentResult DataHPreextend (
                     DataHandler dh,
                     unsigned long maxToAdd,
                     unsigned long *spaceAdded);
dh
Identifies the calling program's connection to your data handler component.

maxToAdd
Specifies the amount of space to add to the current data reference, in bytes. If the client program sets this parameter to 0, your component should add as much space as it can.

spaceAdded
Contains a pointer to an unsigned long. Your component returns the number of bytes it was able to add to the data reference, in bytes.

DISCUSSION

This function is essentially analogous to the File Manager's PBAllocContig function. Your component should allocate contiguous free space. If there is not sufficient contiguous free space to satisfy the request, your component should return a dskFulErr error code.

Client programs use this function in order to avoid incurring any space-allocation delay when capturing movie data.


© 1999 Apple Computer, Inc.

| Previous | Chapter Contents | Chapter Top | Next |